package org.example1;

import java.util.ArrayList;
import java.util.Collections;

/**
 * @Author: 滴滴滴
 * @CreateTime: 2024-11-02
 * @Description: 游戏
 * @Version: 1.0
 */

public class PokerGame {
    //牌盒
    static ArrayList<String> list = new ArrayList<>();

    //静态代码块
    //特点：随着类的加载而加载而且只加载一次
    static {
        //准备牌
        String[] color = {"♣","♦","♥","♠"};
        String[] number = {"2","3","4","5","6","7","8","9","10","J","Q","K","A"};

        for (String c : color) {
            //c依次表示每一种花色
            for (String n : number) {
                //n依次表示每一个数字
                list.add(c+n);
            }
        }
        list.add("大王");
        list.add("小王");
    }
    public  PokerGame(){
        //洗牌
        //打乱集合中的顺序
        Collections.shuffle(list);
        //发牌
        ArrayList<String> lord = new ArrayList<>();//底牌
        ArrayList<String> player1 = new ArrayList<>();
        ArrayList<String> player2 = new ArrayList<>();
        ArrayList<String> player3 = new ArrayList<>();

        //遍历牌盒中每一张牌
        for (int i = 0; i < list.size(); i++) {
            String poker = list.get(i);
            if (i <= 2){
                lord.add(poker);
                continue;
            }
            //接下来给三个玩家发牌
            if (i % 3 == 0){
                player1.add(poker);
            }else if(i % 3 == 1){
                player2.add(poker);
            }else {
                player3.add(poker);
            }
        }
        //看牌
        lookPoker("底牌",lord);
        lookPoker("老壳痛",player1);
        lookPoker("大帅比",player2);
        lookPoker("小蛋筒",player3);
    }

//    参数一：玩家的名字
//    参数二：每个玩家的牌
    public void lookPoker(String name, ArrayList<String> list){
        System.out.println(name + ":");
        for (String poker : list) {
            System.out.print(poker + " ");
        }
        System.out.println();
    }
}
